Skip to main content

Prometheus

Introduction

Prometheus was created to monitor highly dynamic container environments like kubernetes, docker, swarm, etc however it can also be used in a traditional non container infrastructure where you have just bare servers with applications deployed directly on em so over the past years Prometheus has become the mainstream monitoring tool of choice in container and micro service world.

Architecture of Prometheus

components

  • Client Libraries: In code you control, you may both specify a metric and add the instrumentation you want inline with the help of client libraries.

  • Exporters: An exporter is installed alongside the programme from which you wish to extract metrics. It takes request from prometheus, collect the needed data from the application, transform them in required format and renturns to prometheus.

  • Scraping: Prometheus needs to fetch the metrics given by a list of targets given by service discovery and relabelling, prometheus does this by sending a HTTP request callled scrape. It happen regularly for each target, you'd typically schedule it to happen every 10 to 60 seconds.

  • Dashboards: Prometheus has a variety of HTTP APIs that let you request raw data as well as analyse PromQL queries. But using Grafana for dashboards is the best way which includes wide variety of dashboards and features.
    dashboard

  • Alert Management: It is used for converting alerts into notifications which includes email, slack, and and other notification services. With alert management, related alerts can be aggregated to one notification and different outputs and routing can be configured for different teams.

Prometheus Metric Types

It monitors four metric types:

  • Counter: It is the simplest metric, As its name suggests It is useful for monitoring values that can only increase and once value reaches a given number, counter is set to zero.
  • Gauge: This metric measure values that rise and fall, it covers things like current memory utilisation and the number of queries running at the same time.
  • Summary: It shows the total number of observations and sum of observed values.
  • Histogram: This metric is for sampling request durations, response sizes, and similar observations. It generally counts in buckets and gives you the total of all the data you've seen.

Use Cases of Prometheus

Modern DevOps is becoming more and more complex to handle manually and therefore needs more automation,

  • Prometheus assists us in this area by scraping data from the endpoint using query language (PromQL).
  • Promethus can monitor Linux/Windows server, Web server, Stateless application and statefull applications.
  • Prometheus can also be integrate with grafana to visualise the metrics data for analysis.
  • We can trigger the alters if something is misconfigured or high traffic in the application.

When not to use Prometheus

Let's take a look at some scenarios where Prometheus isn't the best choice,

  • Prometheus is not good option to store event logs or individual events as a metrics-based solution. It's also not the greatest option for data with a lot of cardinality, such as email addresses or usernames.
  • Applications involving money or billing, Prometheus should be used with caution because prometheus is designed for operational monitoring, where small inaccuracies and race conditions due to factors like kernel scheduling and failed scrapes are a fact of life.